/*
 * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.icesoft.framework.core.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.icesoft.framework.core.annotation.Entity;
import com.icesoft.framework.core.binding.query.BindQuery;
import com.icesoft.framework.core.binding.query.Comparison;
import com.icesoft.framework.core.config.Cons;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 数据字典实体
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("tb_dictionary")
@Entity(module = "core", describe = "数据字典")
public class Dictionary extends BaseEntity {
	private static final long serialVersionUID = 11301L;

	/**
	 * 默认逻辑删除标记，is_deleted=0有效
	 */
	@TableLogic
	@JsonIgnore
	@TableField(value = Cons.COLUMN_IS_DELETED, select = false)
	@Column(value = "deleted", comment = "逻辑删除")
	protected boolean deleted = false;

	/**
	 * 租户ID
	 */
	@JsonIgnore
	@TableField
	@Column(value = "tenant_id", comment = "租户ID", type = MySqlTypeConstant.BIGINT)
	private Long tenantId;

	/***
	 * 上级ID
	 */
	@NotNull(message = "上级ID不能为空，如无请设为0")
	@TableField
	@Column(value = "parent_id", comment = "上级", type = MySqlTypeConstant.BIGINT)
	private Long parentId = 0L;

	/***
	 * 数据字典类型
	 */
	@NotNull(message = "数据字典类型不能为空！")
	@Length(max = 50, message = "数据字典类型长度超长！")
	@TableField
	@Column(value = "type", comment = "数据字典类型", type = MySqlTypeConstant.VARCHAR)
	private String type;

	@BindQuery(comparison = Comparison.LIKE)
	@TableField
	@Column(value = "item_code", comment = "数据字典项的取值", type = MySqlTypeConstant.VARCHAR)
	private String itemCode;

	/***
	 * 数据字典项的显示名称
	 */
	@NotNull(message = "数据字典项名称不能为空！")
	@Length(max = 100, message = "数据字典项名称长度超长！")
	@BindQuery(comparison = Comparison.LIKE)
	@TableField
	@Column(value = "item_name", comment = "数据字典项的显示名称", type = MySqlTypeConstant.VARCHAR)
	private String itemName;

	/***
	 * 数据字典项的存储值（编码）
	 */
	@Length(max = 100, message = "数据字典项编码长度超长！")
	@TableField
	@Column(value = "item_value", comment = "数据字典项的存储值", type = MySqlTypeConstant.VARCHAR)
	private String itemValue;

	/***
	 * 备注信息
	 */
	@Length(max = 200, message = "数据字典备注长度超长！")
	@TableField
	@Column(value = "description", comment = "备注信息", type = MySqlTypeConstant.VARCHAR)
	private String description;

	/***
	 * 排序号
	 */
	@TableField
	@Column(value = "sort_id", comment = "排序号", type = MySqlTypeConstant.BIGINT)
	private Integer sortId;

	@TableField
	@Column(value = "extdata", comment = "扩展数据", type = MySqlTypeConstant.VARCHAR)
	private String extdata; //扩展数据

	@TableField(exist = false)
	private Map<String, Object> extdataMap;

}
